<template>
  <el-row class="warp">
    <el-col :span="24" class="warp-breadcrum">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }"><b>首页</b></el-breadcrumb-item>
        <el-breadcrumb-item>图书管理</el-breadcrumb-item>
      </el-breadcrumb>
    </el-col>

    <el-col :span="24" class="warp-main" v-loading="loading" element-loading-text="拼命加载中">
      <!--工具条-->
      <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
        <el-form role="form" size="small" id="projectForm" class="form-horizontal details">
          <el-row>
            <el-col :xs="6" :lg="6" :sm="6" :md="6">
              <el-form-item :label-width="formLabelWidth" label="书名:">
                <el-input size="mini" type="text" v-model="filters.name" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="6" :lg="6" :sm="6" :md="6">
              <el-form-item :label-width="formLabelWidth" label="作者:">
                <el-input size="mini" type="text" v-model="filters.name" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="6" :lg="6" :sm="6" :md="6">
              <el-form-item :label-width="formLabelWidth" label="分类:">
                <el-select size="mini" v-model="filters.classification" placeholder="请选择分类">
                  <el-option
                    v-for="item in classificationList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="6" :lg="6" :sm="6" :md="6" style="text-align: right;">
              <el-form-item label-width="0px">
                <el-button :loading="loading" router-preventReClick size="mini" type="primary" plain icon="el-icon-search" @click="handleSearch">查询</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-col>

      <!--列表-->
      <el-table :data="dataList" highlight-current-row @selection-change="selsChange" style="width: 100%;">
        <el-table-column type="index" width="60"></el-table-column>
        <el-table-column prop="name" label="书名"></el-table-column>
        <el-table-column prop="author" label="作者"></el-table-column>
        <el-table-column prop="classification" label="分类" :formatter="classificationFormat"></el-table-column>
        <el-table-column prop="count" label="数量"></el-table-column>
      </el-table>

      <!--工具条-->
      <el-col size="mini" :span="24" class="toolbar">
        <el-pagination
          style="margin-top: 10px"
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </el-col>

    </el-col>
  </el-row>
</template>
<script>
  import api from '@/api/apiBook';
  import addForm from "../book/components/addForm.vue";

  export default {
    data() {
      return {
        colLayOut: {xs: 12,sm:12,md:6, lg: 6},
        formLabelWidth: "160px",
        filters: {
          name: ''
        },
        dataList: [],
        total: 0,
        page: 1,
        pageSize: 10,
        loading: false,
        showQueryCondition: false,
        classificationList:[
          {value: 1,label: '语文'},
          {value: 2,label: '数学'}
        ],
      }
    },
    //组件
    components: {
      addForm
    },
    //方法
    methods: {
      handleSizeChange(val) {
        this.pageSize = val;
        this.search();
      },
      handleCurrentChange(val) {
        this.page = val;
        this.search();
      },
      handleSearch() {
        this.search();
      },
      search() {
        let that = this;
        let params = {
          pageNo: that.page,
          pageSize: that.pageSize,
          ...this.filters,
        };

        that.loading = true;
        api.listByPage(params, (result)=>{
          if (result.code == '0') {
            that.loading = false;
            if (result && result.page.list) {
              that.total = result.page.total;
              that.dataList = result.page.list;
            }
          } else {
            that.loading = false;
            that.$message. error({
              showClose: true,
              message: result.msg,
              duration: 2000
            });
          }
        });

      },
      selsChange(sels) {
        this.sels = sels;
      },
      delFormat(row,cloumn){
        if (row.del == 0) {
          return "否";
        }  else {
          return "是";
        }
      },
      classificationFormat(row,cloumn){
        if (row.classification == 1) {return "语文";}
        else if(row.classification == 2) {return "数学";}
        else if(row.classification == 3) {return "外语";}
        else if(row.classification == 4) {return "物理";}
        else if(row.classification == 5) {return "化学";}
        else if(row.classification == 6) {return "生物";}
        else if(row.classification == 7) {return "历史";}
        else if(row.classification == 8) {return "政治";}
        else if(row.classification == 9) {return "地理";}
        else if(row.classification == 10) {return "音乐";}
        else if(row.classification == 11) {return "美术";}
        else if(row.classification == 12) {return "体育";}
        else if(row.classification == 13) {return "其他";}
      },
    },
    mounted() {
      this.handleSearch()

    }
  }
</script>

